<template>
  <!-- 这是一个无渲染组件，只负责权限监听 -->
  <div style="display: none;"></div>
</template>

<script setup>
import { onMounted, onUnmounted } from 'vue'
import { useStore } from 'vuex'
// import { ElMessage } from 'element-plus' // 已移除未使用
// import { useRouter } from 'vue-router' // 已移除未使用

const store = useStore()
let permissionCheckInterval = null

// 检查权限变化
const checkPermissionChanges = async () => {
  try {
    // 只有在有token的情况下才检查权限
    const token = store.state.user.token
    if (token) {
    await store.dispatch('user/refreshUserInfo')
    }
  } catch (error) {
    console.error('Permission check failed:', error)
  }
}

// 开始权限监听
const startPermissionWatching = () => {
  // 只有在有token的情况下才开始监听
  const token = store.state.user.token
  if (token) {
  // 每30秒检查一次权限变化
  permissionCheckInterval = setInterval(checkPermissionChanges, 30000)
  }
}

// 停止权限监听
const stopPermissionWatching = () => {
  if (permissionCheckInterval) {
    clearInterval(permissionCheckInterval)
    permissionCheckInterval = null
  }
}

onMounted(() => {
  startPermissionWatching()
})

onUnmounted(() => {
  stopPermissionWatching()
})
</script> 